package com.beamfield.common;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/6/6 0006.
 */
public class MyGenerator {
    public static void main(String[] args) {
        System.out.println("Start Create DB Code!");

        List<String> warnings = new ArrayList<String>();
        boolean overwrite = true;
        File configFile = new File("src/main/resources/generatorConfig.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config;
        try {
            config = cp.parseConfiguration(configFile);
            DefaultShellCallback defaultShellCallback = new DefaultShellCallback(overwrite);
            MyBatisGenerator myBatisGenerator;
            try {
                myBatisGenerator = new MyBatisGenerator(config, defaultShellCallback, warnings);
                myBatisGenerator.generate(null);
            } catch (Exception e) {
                System.out.println("Create DB Code error!");
                e.printStackTrace();
            }
        } catch (Exception e) {
            System.out.println("Create DB Code error!");
            e.printStackTrace();
        }
        if(!warnings.isEmpty()){
            System.out.println(warnings);
        }
    }
}
